'''
Author: xushaocong
Date: 2022-07-03 22:42:15
LastEditTime: 2022-07-03 22:53:21
LastEditors: xushaocong
Description: 
FilePath: /tmp/utils/utils.py
email: xushaocong@stu.xmu.edu.cn
'''


import cv2 

import glob
import os 
from tqdm import tqdm
import  os.path as osp

def imgs2video(all_img_path,video_name,fps=20,mode =1):
    
    # print(all_img)
    img = cv2.imread(all_img_path[0])

    h,w,c = img.shape
    print(img.shape,h,w,c )
    size=(w,h)
    
    fourcc = cv2.VideoWriter_fourcc(*'mp4v')
    videoWriter = cv2.VideoWriter(video_name,fourcc,fps,size)#最后一个是保存图片的尺寸


    for im in tqdm(all_img_path):
        frame = cv2.imread(im)
        videoWriter.write(frame)
    videoWriter.release()
    cv2.destroyAllWindows()
    

if __name__ == "__main__":
    p = "/home/DISCOVER_summer2022/xusc/exp/tmp/vis"
    all_ = sorted(glob.glob(p+"/*.jpg"))
    
    video_name = "/home/DISCOVER_summer2022/xusc/exp/tmp/procedure_plot.mp4"
    imgs2video(all_,video_name)
